<?php
 /**
 * Quick email
 * 
 * @author: trungdt
 * @since: Mar 10, 2011
 * @version: 1.0
 * 
 * Change logs
 */
 
if (!defined("EXPONENT")) exit("");
    $demand = null;        
    // build localtion
    $loc=null;
    $loc->mod="demandmodule";
    
    if (isset($_POST['id'])) {
        $demand = $db->selectObject('demands', 'id='.intval($_POST['id']));
    } else {
        
    }
    
    //if (exponent_permissions_check("manage",$loc)) {   
    // we can continue if 
    // - this user has administrate or approve demand permission
    // - this user is the owner of this record (post new) 
    if (
    (exponent_permissions_check("administrate",$loc) ||
     exponent_permissions_check("approve_demand",$loc)) && 
     isset($demand->id)
    ) 
    {
      if ($demand->status < 2 || !isset($_REQUEST['add'])) // this demand is not approved
      {
          die();
      }
      else
      {
          $sendmail=intval($_REQUEST['add']);
          if (($sendmail != 0) && ($sendmail !=1))
          {
              $sendmail=0;
          }
          $sql="UPDATE {$db->prefix}demands 
            SET sendmail={$sendmail}
            WHERE id = {$demand->id}";
          $db->sql($sql);
          echo $demand->id;
      }
    } else {
        die();
    }
?>
